<?php

// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org 
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------


namespace app\common\model;


use think\Model;
use think\model\concern\SoftDelete;

/**
 * 有关时间的模型
 * Class TimeModel
 * @package app\common\model
 */
class TimeModel extends Model
{

    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    /**
     * 软删除
     */
    use SoftDelete;
    protected $deleteTime = false;


    /**
     * 记录日志
     *
     * @param string $path
     * @param string $data
     * @param int $need_chain
     * @return bool
     */
    public static function writeLog($data=array(), $path='')
    {

        is_array($data) ?: $data = ['data' => $data];
        if(true){
            $backtrace_info = debug_backtrace()[1];
            $data['backtrace_ca'] = $backtrace_info['class'] .'.' .$backtrace_info['function'];
        }
        $data['ip'] = getIp();
        $data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
        $path ?: $path = request()->controller() .'_' .request()->action();
        write_log($path, $data);
        return true;
    }
}